package site.fantasycube.blog.service.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import site.fantasycube.blog.domain.BlogUser;
import site.fantasycube.blog.mapper.UserMapper;
import site.fantasycube.blog.service.IUserService;

/**
 * @author 幻&乐
 * @Date 2021/12/26
 * 描述 用户服务业务层
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, BlogUser> implements IUserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public BlogUser getByUserName(String username) {
        return lambdaQuery().eq(BlogUser::getUsername, username).one();
    }

    @Override
    @Transactional
    public  BlogUser registration(BlogUser entity) {
        String id = userMapper.registration(entity);
        if (StringUtils.isEmpty(id)){
            return null;
        }
        entity.setPassword("********");
        return entity.setUid(id);
    }

    @Override
    public BlogUser getByEmail(String email) {
        return lambdaQuery().eq(BlogUser::getEmail, email).one();
    }

}
